new method, gtk_widget_modify_cursor() (#89314).
authorYevgen Muntyan <muntyan@tamu.edu>
Wed, 6 Jun 2007 19:43:31 +0000 (19:43 +0000)
committerYevgen Muntyan <muntyan@src.gnome.org>
Wed, 6 Jun 2007 19:43:31 +0000 (19:43 +0000)
2007-06-06  Yevgen Muntyan  <muntyan@tamu.edu>

* gtk/gtkwidget.c:
* gtk/gtkwidget.h: new method, gtk_widget_modify_cursor() (#89314).

* gtkrc.c:
* gtkrc.h: new functions _gtk_rc_style_set_rc_property() and
_gtk_rc_style_unset_rc_property().

* gtk/gtk.symbols: added gtk_widget_modify_cursor.

* tests/testtext.c (do_cursor_visible_changed):
* tests/testgtk.c (create_styles): test it.

svn path=/trunk/; revision=18066

ChangeLog
gtk/gtk.symbols
gtk/gtkrc.c
gtk/gtkrc.h
gtk/gtkwidget.c
gtk/gtkwidget.h
tests/testgtk.c
tests/testtext.c

index 8247b9a3614f347d0d7a02f0022ab89e890bc44f..99a02a3c5e900d6e35ae138fbefad87c7b38ba45 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-06-06  Yevgen Muntyan  <muntyan@tamu.edu>
+
+       * gtk/gtkwidget.c:
+       * gtk/gtkwidget.h: new method, gtk_widget_modify_cursor() (#89314).
+       
+       * gtkrc.c:
+       * gtkrc.h: new functions _gtk_rc_style_set_rc_property() and 
+       _gtk_rc_style_unset_rc_property().
+       
+       * gtk/gtk.symbols: added gtk_widget_modify_cursor.
+       
+       * tests/testtext.c (do_cursor_visible_changed):
+       * tests/testgtk.c (create_styles): test it.
+
 2007-06-06  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkevents-quartz.c (find_mouse_window_for_ns_event)
index b2ee34588c52b57f1b551b9af092dac40b6d77cf..69694376fa45e779d9bb8a912ef6c591c294952b 100644 (file)
@@ -4607,6 +4607,7 @@ gtk_widget_mnemonic_activate
 gtk_widget_modify_base
 gtk_widget_modify_bg
 gtk_widget_modify_fg
+gtk_widget_modify_cursor
 gtk_widget_modify_font
 gtk_widget_modify_style
 gtk_widget_modify_text
index 5ca60172431a38320b9e77b4777a885af62a66f3..324b37a49ba01a5102a2efec7e9886419f39d379 100644 (file)
@@ -240,6 +240,10 @@ static gint           gtk_rc_properties_cmp             (gconstpointer    bsearch_node1,
                                                      gconstpointer    bsearch_node2);
 static void        gtk_rc_set_free                   (GtkRcSet        *rc_set);
 
+static void       insert_rc_property                (GtkRcStyle      *style,
+                                                     GtkRcProperty   *property,
+                                                     gboolean         replace);
+
 
 static const GScannerConfig gtk_rc_scanner_config =
 {
@@ -1265,6 +1269,36 @@ gtk_rc_style_copy (GtkRcStyle *orig)
   return style;
 }
 
+void
+_gtk_rc_style_set_rc_property (GtkRcStyle *rc_style,
+                              GtkRcProperty *property)
+{
+  g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
+  g_return_if_fail (property != NULL);
+
+  insert_rc_property (rc_style, property, TRUE);
+}
+
+void
+_gtk_rc_style_unset_rc_property (GtkRcStyle *rc_style,
+                                GQuark      type_name,
+                                GQuark      property_name)
+{
+  GtkRcProperty *node;
+
+  g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
+
+  node = _gtk_rc_style_lookup_rc_property (rc_style, type_name, property_name);
+
+  if (node != NULL)
+    {
+      guint index = node - (GtkRcProperty *) rc_style->rc_properties->data;
+      g_value_unset (&node->value);
+      g_free (node->origin);
+      g_array_remove_index (rc_style->rc_properties, index);
+    }
+}
+
 void      
 gtk_rc_style_ref (GtkRcStyle *rc_style)
 {
index e14277719df9f08c2cab55776110bbb46443c618..a64343c45ef4e54f475a6672945f6892e1166721 100644 (file)
@@ -248,6 +248,11 @@ struct _GtkRcProperty
 const GtkRcProperty* _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
                                                       GQuark      type_name,
                                                       GQuark      property_name);
+void         _gtk_rc_style_set_rc_property           (GtkRcStyle *rc_style,
+                                                      GtkRcProperty *property);
+void         _gtk_rc_style_unset_rc_property         (GtkRcStyle *rc_style,
+                                                      GQuark      type_name,
+                                                      GQuark      property_name);
 
 GSList     * _gtk_rc_style_get_color_hashes        (GtkRcStyle *rc_style);
 
index 59e91f81a4f90c6ddf3370f282e08ea2baba879a..62245c1af258c515f61cf7daae3056c5efc10eaa 100644 (file)
@@ -5400,6 +5400,68 @@ gtk_widget_modify_base (GtkWidget      *widget,
   gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
 }
 
+static void
+modify_color_property (GtkWidget      *widget,
+                      GtkRcStyle     *rc_style,
+                      const char     *name,
+                      const GdkColor *color)
+{
+  GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
+  GQuark property_name = g_quark_from_string (name);
+
+  if (color)
+    {
+      GtkRcProperty rc_property = {0};
+      char *color_name;
+
+      rc_property.type_name = type_name;
+      rc_property.property_name = property_name;
+      rc_property.origin = NULL;
+
+      color_name = gdk_color_to_string (color);
+      g_value_init (&rc_property.value, G_TYPE_STRING);
+      g_value_take_string (&rc_property.value, color_name);
+
+      _gtk_rc_style_set_rc_property (rc_style, &rc_property);
+
+      g_value_unset (&rc_property.value);
+    }
+  else
+    _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
+}
+
+/**
+ * gtk_widget_modify_cursor:
+ * @widget: a #GtkWidget
+ * @primary: the color to use for primary cursor (does not need to be
+ *           allocated), or %NULL to undo the effect of previous calls to
+ *           of gtk_widget_modify_cursor().
+ * @secondary: the color to use for secondary cursor (does not need to be
+ *             allocated), or %NULL to undo the effect of previous calls to
+ *             of gtk_widget_modify_cursor().
+ *
+ * Sets the font to use for a widget.  All other style values are left
+ * untouched. See also gtk_widget_modify_style().
+ *
+ * Since: 2.12
+ **/
+void
+gtk_widget_modify_cursor (GtkWidget      *widget,
+                         const GdkColor *primary,
+                         const GdkColor *secondary)
+{
+  GtkRcStyle *rc_style;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  rc_style = gtk_widget_get_modifier_style (widget);
+
+  modify_color_property (widget, rc_style, "cursor-color", primary);
+  modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
+
+  gtk_widget_modify_style (widget, rc_style);
+}
+
 /**
  * gtk_widget_modify_font:
  * @widget: a #GtkWidget
index 50374cc85aa42ac571f9c36fbd2034744e719961..8db67c10c0b23ba6d5dce9d8004b34002cbae4eb 100644 (file)
@@ -671,6 +671,9 @@ void        gtk_widget_modify_text        (GtkWidget            *widget,
 void        gtk_widget_modify_base        (GtkWidget            *widget,
                                           GtkStateType          state,
                                           const GdkColor       *color);
+void        gtk_widget_modify_cursor      (GtkWidget            *widget,
+                                          const GdkColor       *primary,
+                                          const GdkColor       *secondary);
 void        gtk_widget_modify_font        (GtkWidget            *widget,
                                           PangoFontDescription *font_desc);
 
index 44eb4fcc50ee0529460a865feeb11838a8c9ad68..be779a8791d5a9f76964e4a0f3e1d2a4a3d133de 100644 (file)
@@ -13366,6 +13366,15 @@ create_styles (GtkWidget *widget)
       gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &yellow);
       gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
 
+      label = gtk_label_new ("Cursor:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      entry = gtk_entry_new ();
+      gtk_entry_set_text (GTK_ENTRY (entry), "Some Text");
+      gtk_widget_modify_cursor (entry, &red, &red);
+      gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+
       label = gtk_label_new ("Multiple:");
       gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
       gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
index b1f6f532a037f47d616b972c5b6639329b6f740b..af826b6cccca02d8d8fe4f21099f93281fc23d38 100644 (file)
@@ -983,6 +983,19 @@ do_editable_changed (gpointer callback_data,
   gtk_text_view_set_editable (GTK_TEXT_VIEW (view->text_view), callback_action);
 }
 
+static void
+change_cursor_color (GtkWidget *widget,
+                    gboolean   set)
+{
+  if (set)
+    {
+      GdkColor red = {0, 65535, 0, 0};
+      gtk_widget_modify_cursor (widget, &red, &red);
+    }
+  else
+    gtk_widget_modify_cursor (widget, NULL, NULL);
+}
+
 static void
 do_cursor_visible_changed (gpointer callback_data,
                            guint callback_action,
@@ -990,7 +1003,20 @@ do_cursor_visible_changed (gpointer callback_data,
 {
   View *view = view_from_widget (widget);
 
-  gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view->text_view), callback_action);
+  switch (callback_action)
+    {
+    case 0:
+      gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view->text_view), FALSE);
+      break;
+    case 1:
+      gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view->text_view), TRUE);
+      change_cursor_color (view->text_view, FALSE);
+      break;
+    case 2:
+      gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view->text_view), TRUE);
+      change_cursor_color (view->text_view, TRUE);
+      break;
+    }
 }
 
 static void
@@ -1946,8 +1972,9 @@ static GtkItemFactoryEntry menu_items[] =
   { "/Settings/Not editable",    NULL,      do_editable_changed,  FALSE, "/Settings/Editable" },
   { "/Settings/sep1",        NULL,      NULL,             0, "<Separator>" },
 
-  { "/Settings/Cursor visible",    NULL,      do_cursor_visible_changed,  TRUE, "<RadioItem>" },
-  { "/Settings/Cursor not visible", NULL,      do_cursor_visible_changed,  FALSE, "/Settings/Cursor visible" },
+  { "/Settings/Cursor normal",    NULL,      do_cursor_visible_changed,  1, "<RadioItem>" },
+  { "/Settings/Cursor not visible", NULL,      do_cursor_visible_changed,  0, "/Settings/Cursor normal" },
+  { "/Settings/Cursor colored", NULL,      do_cursor_visible_changed,  2, "/Settings/Cursor normal" },
   { "/Settings/sep1",        NULL,      NULL,          0, "<Separator>" },
   
   { "/Settings/Left-to-Right", NULL,    do_direction_changed,  GTK_TEXT_DIR_LTR, "<RadioItem>" },